{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1-final"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python_defaultSpec_1597372376395",
   "display_name": "Python 3.7.1 64-bit ('base': conda)"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys; sys.path.append(\"C:/GitWorks/pdb-profiling\")\n",
    "from pdb_profiling.fetcher.webfetch import UnsyncFetch\n",
    "from pdb_profiling.processers.pdbe.api import ProcessPDBe\n",
    "from pdb_profiling.processers.pdbe.record import PDB, API_SET, PDBAssemble"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from time import perf_counter\n",
    "from pdb_profiling.utils import related_dataframe\n",
    "from pprint import pprint\n",
    "from unsync import unsync\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "ProcessPDBe.use_existing = True\n",
    "ProcessPDBe.init_logger()\n",
    "UnsyncFetch.use_existing = True\n",
    "UnsyncFetch.set_logger(ProcessPDBe.logger)\n",
    "PDB.set_web_semaphore(30)\n",
    "PDB.set_folder('./demo/')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "tags": []
   },
   "source": [
    "```py\n",
    "pdb_6ozg = PDB('6ozg', './demo/')\n",
    "pdb_1lo8 = PDB('1lo8', './demo/')\n",
    "pdb_2q88 = PDB('2q88', './demo/')\n",
    "pdb_2aw3 = PDB('2aw3', './demo/')\n",
    "pdb_1akq = PDB('1akq', './demo/')\n",
    "# sequence\n",
    "start = perf_counter()\n",
    "pdb_6ozg.res2eec(merge_with_molecules_info=False).result()\n",
    "pdb_1lo8.res2eec(merge_with_molecules_info=False).result()\n",
    "pdb_2q88.res2eec(merge_with_molecules_info=False).result()\n",
    "pdb_2aw3.res2eec(merge_with_molecules_info=False).result()\n",
    "pdb_1akq.res2eec(merge_with_molecules_info=False).result()\n",
    "print(perf_counter()-start)\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "output_type": "stream",
     "name": "stderr",
     "text": "100%|██████████| 6/6 [00:03<00:00,  1.90it/s]Wall time: 3.17 s\n\n"
    }
   ],
   "source": [
    "pdb_6ozg = PDB('6ozg')\n",
    "pdb_1lo8 = PDB('1lo8')\n",
    "pdb_2q88 = PDB('2q88')\n",
    "pdb_2aw3 = PDB('2aw3')\n",
    "pdb_1akq = PDB('1akq')\n",
    "pdb_3ue7 = PDB('3ue7')\n",
    "# loop\n",
    "tasks = (pdb_6ozg.set_res2eec_df(),\n",
    "pdb_1lo8.set_res2eec_df(),\n",
    "pdb_2q88.set_res2eec_df(),\n",
    "pdb_2aw3.set_res2eec_df(),\n",
    "pdb_1akq.set_res2eec_df(),\n",
    "pdb_3ue7.set_res2eec_df())\n",
    "%time res = UnsyncFetch.unsync_tasks(tasks).result()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### without assembly\n",
    "\n",
    "```py\n",
    "pdb_1oo9 = PDB('1oo9')\n",
    "pdb_1oo9.set_assembly().result()\n",
    "pdb_1oo9.assembly\n",
    "'''{0: <PDBAssemble 1oo9/0>}'''\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "{'api/mappings/all_isoforms/',\n 'api/pdb/entry/assembly/',\n 'api/pdb/entry/binding_sites/',\n 'api/pdb/entry/carbohydrate_polymer/',\n 'api/pdb/entry/cofactor/',\n 'api/pdb/entry/drugbank/',\n 'api/pdb/entry/electron_density_statistics/',\n 'api/pdb/entry/experiment/',\n 'api/pdb/entry/files/',\n 'api/pdb/entry/ligand_monomers/',\n 'api/pdb/entry/modified_AA_or_NA/',\n 'api/pdb/entry/molecules/',\n 'api/pdb/entry/mutated_AA_or_NA/',\n 'api/pdb/entry/observed_residues_ratio/',\n 'api/pdb/entry/polymer_coverage/',\n 'api/pdb/entry/related_experiment_data/',\n 'api/pdb/entry/residue_listing/',\n 'api/pdb/entry/secondary_structure/',\n 'api/pdb/entry/status/',\n 'api/pdb/entry/summary/',\n 'api/pisa/interfacedetail/',\n 'api/pisa/interfacelist/'}"
     },
     "metadata": {},
     "execution_count": 5
    }
   ],
   "source": [
    "API_SET"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "{1: <PDBInterface 1oo9/0/1>}"
     },
     "metadata": {},
     "execution_count": 6
    }
   ],
   "source": [
    "pdb_1oo9_1 = PDBAssemble('1oo9/0')\n",
    "pdb_1oo9_1.set_interface().result()\n",
    "pdb_1oo9_1.interface"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "Wall time: 4.57 s\n"
    },
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "  pdb_id entity_id chain_id struct_asym_id struct_asym_id_in_assembly  \\\n0   1oo9         1        A              A                          A   \n1   1oo9         2        B              B                          B   \n0   1oo9         1        A              A                          A   \n1   1oo9         2        B              B                          B   \n\n    molecule_type                      molecule_name  assembly_id  \\\n0  polypeptide(L)                  [\"Stromelysin-1\"]            0   \n1  polypeptide(L)  [\"Metalloproteinase inhibitor 1\"]            0   \n0  polypeptide(L)                  [\"Stromelysin-1\"]            1   \n1  polypeptide(L)  [\"Metalloproteinase inhibitor 1\"]            1   \n\n           details  asym_id_rank  \n0  asymmetric_unit             1  \n1  asymmetric_unit             1  \n0              NaN             1  \n1              NaN             1  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>pdb_id</th>\n      <th>entity_id</th>\n      <th>chain_id</th>\n      <th>struct_asym_id</th>\n      <th>struct_asym_id_in_assembly</th>\n      <th>molecule_type</th>\n      <th>molecule_name</th>\n      <th>assembly_id</th>\n      <th>details</th>\n      <th>asym_id_rank</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>1oo9</td>\n      <td>1</td>\n      <td>A</td>\n      <td>A</td>\n      <td>A</td>\n      <td>polypeptide(L)</td>\n      <td>[\"Stromelysin-1\"]</td>\n      <td>0</td>\n      <td>asymmetric_unit</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>1oo9</td>\n      <td>2</td>\n      <td>B</td>\n      <td>B</td>\n      <td>B</td>\n      <td>polypeptide(L)</td>\n      <td>[\"Metalloproteinase inhibitor 1\"]</td>\n      <td>0</td>\n      <td>asymmetric_unit</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>0</th>\n      <td>1oo9</td>\n      <td>1</td>\n      <td>A</td>\n      <td>A</td>\n      <td>A</td>\n      <td>polypeptide(L)</td>\n      <td>[\"Stromelysin-1\"]</td>\n      <td>1</td>\n      <td>NaN</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>1oo9</td>\n      <td>2</td>\n      <td>B</td>\n      <td>B</td>\n      <td>B</td>\n      <td>polypeptide(L)</td>\n      <td>[\"Metalloproteinase inhibitor 1\"]</td>\n      <td>1</td>\n      <td>NaN</td>\n      <td>1</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "metadata": {},
     "execution_count": 7
    }
   ],
   "source": [
    "%time PDB('1oo9').get_eec_as_df().result()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "chain_id struct_asym_id entity_id pdb_id struct_asym_id_in_assembly\n0        B              B         1   2ony                          B\n1        A              A         1   2ony                          A\n"
    },
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "                                                                                             0  \\\npdb_id                                                                                    2ony   \nentity_id                                                                                    1   \nchain_id                                                                                     A   \nstruct_asym_id                                                                               A   \nstruct_asym_id_in_assembly                                                                   A   \nca_p_only                                                                                False   \ngene_name                                                                      [\"PENT\",\"PNMT\"]   \nin_chains                                                                            [\"A\",\"B\"]   \nin_struct_asyms                                                                      [\"A\",\"B\"]   \nlength                                                                                     289   \nmolecule_name                                       [\"Phenylethanolamine N-methyltransferase\"]   \nmolecule_type                                                                   polypeptide(L)   \nmutation_flag                                                                              NaN   \nnumber_of_copies                                                                             2   \npdb_sequence                                 MSGADRSPNAGAAPDSAPGQAAVASAYQRFEPRAYLRNNYAPPRGD...   \npdb_sequence_indices_with_multiple_residues                                                 {}   \nsample_preparation                                                     Genetically manipulated   \nsequence                                     MSGADRSPNAGAAPDSAPGQAAVASAYQRFEPRAYLRNNYAPPRGD...   \nsource                                       [{\"mappings\":[{\"start\":{\"residue_number\":1},\"e...   \nsynonym                                                 Phenylethanolamine N-methyltransferase   \nweight                                                                                   31846   \n\n                                                                                             1  \\\npdb_id                                                                                    2ony   \nentity_id                                                                                    1   \nchain_id                                                                                     B   \nstruct_asym_id                                                                               B   \nstruct_asym_id_in_assembly                                                                   B   \nca_p_only                                                                                False   \ngene_name                                                                      [\"PENT\",\"PNMT\"]   \nin_chains                                                                            [\"A\",\"B\"]   \nin_struct_asyms                                                                      [\"A\",\"B\"]   \nlength                                                                                     289   \nmolecule_name                                       [\"Phenylethanolamine N-methyltransferase\"]   \nmolecule_type                                                                   polypeptide(L)   \nmutation_flag                                                                              NaN   \nnumber_of_copies                                                                             2   \npdb_sequence                                 MSGADRSPNAGAAPDSAPGQAAVASAYQRFEPRAYLRNNYAPPRGD...   \npdb_sequence_indices_with_multiple_residues                                                 {}   \nsample_preparation                                                     Genetically manipulated   \nsequence                                     MSGADRSPNAGAAPDSAPGQAAVASAYQRFEPRAYLRNNYAPPRGD...   \nsource                                       [{\"mappings\":[{\"start\":{\"residue_number\":1},\"e...   \nsynonym                                                 Phenylethanolamine N-methyltransferase   \nweight                                                                                   31846   \n\n                                                                         2  \\\npdb_id                                                                2ony   \nentity_id                                                                2   \nchain_id                                                                 A   \nstruct_asym_id                                                           C   \nstruct_asym_id_in_assembly                                               C   \nca_p_only                                                            False   \ngene_name                                                              NaN   \nin_chains                                                        [\"A\",\"B\"]   \nin_struct_asyms                                                  [\"C\",\"F\"]   \nlength                                                                 NaN   \nmolecule_name                                [\"S-ADENOSYL-L-HOMOCYSTEINE\"]   \nmolecule_type                                                        bound   \nmutation_flag                                                          NaN   \nnumber_of_copies                                                         2   \npdb_sequence                                                           NaN   \npdb_sequence_indices_with_multiple_residues                            NaN   \nsample_preparation                                  Synthetically obtained   \nsequence                                                               NaN   \nsource                                                                 NaN   \nsynonym                                                                NaN   \nweight                                                             384.411   \n\n                                                                         3  \\\npdb_id                                                                2ony   \nentity_id                                                                2   \nchain_id                                                                 B   \nstruct_asym_id                                                           F   \nstruct_asym_id_in_assembly                                               F   \nca_p_only                                                            False   \ngene_name                                                              NaN   \nin_chains                                                        [\"A\",\"B\"]   \nin_struct_asyms                                                  [\"C\",\"F\"]   \nlength                                                                 NaN   \nmolecule_name                                [\"S-ADENOSYL-L-HOMOCYSTEINE\"]   \nmolecule_type                                                        bound   \nmutation_flag                                                          NaN   \nnumber_of_copies                                                         2   \npdb_sequence                                                           NaN   \npdb_sequence_indices_with_multiple_residues                            NaN   \nsample_preparation                                  Synthetically obtained   \nsequence                                                               NaN   \nsource                                                                 NaN   \nsynonym                                                                NaN   \nweight                                                             384.411   \n\n                                                                                             4  \\\npdb_id                                                                                    2ony   \nentity_id                                                                                    3   \nchain_id                                                                                     A   \nstruct_asym_id                                                                               D   \nstruct_asym_id_in_assembly                                                                   D   \nca_p_only                                                                                False   \ngene_name                                                                                  NaN   \nin_chains                                                                                [\"A\"]   \nin_struct_asyms                                                                          [\"D\"]   \nlength                                                                                     NaN   \nmolecule_name                                [\"N-(4-CHLOROPHENYL)-1,2,3,4-TETRAHYDROISOQUIN...   \nmolecule_type                                                                            bound   \nmutation_flag                                                                              NaN   \nnumber_of_copies                                                                             1   \npdb_sequence                                                                               NaN   \npdb_sequence_indices_with_multiple_residues                                                NaN   \nsample_preparation                                                      Synthetically obtained   \nsequence                                                                                   NaN   \nsource                                                                                     NaN   \nsynonym                                                                                    NaN   \nweight                                                                                  322.81   \n\n                                                                  5  \npdb_id                                                         2ony  \nentity_id                                                         4  \nchain_id                                                          B  \nstruct_asym_id                                                    E  \nstruct_asym_id_in_assembly                                        E  \nca_p_only                                                     False  \ngene_name                                                       NaN  \nin_chains                                                     [\"B\"]  \nin_struct_asyms                                               [\"E\"]  \nlength                                                          NaN  \nmolecule_name                                     [\"PHOSPHATE ION\"]  \nmolecule_type                                                 bound  \nmutation_flag                                                   NaN  \nnumber_of_copies                                                  1  \npdb_sequence                                                    NaN  \npdb_sequence_indices_with_multiple_residues                     NaN  \nsample_preparation                           Synthetically obtained  \nsequence                                                        NaN  \nsource                                                          NaN  \nsynonym                                                         NaN  \nweight                                                       94.971  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>0</th>\n      <th>1</th>\n      <th>2</th>\n      <th>3</th>\n      <th>4</th>\n      <th>5</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>pdb_id</th>\n      <td>2ony</td>\n      <td>2ony</td>\n      <td>2ony</td>\n      <td>2ony</td>\n      <td>2ony</td>\n      <td>2ony</td>\n    </tr>\n    <tr>\n      <th>entity_id</th>\n      <td>1</td>\n      <td>1</td>\n      <td>2</td>\n      <td>2</td>\n      <td>3</td>\n      <td>4</td>\n    </tr>\n    <tr>\n      <th>chain_id</th>\n      <td>A</td>\n      <td>B</td>\n      <td>A</td>\n      <td>B</td>\n      <td>A</td>\n      <td>B</td>\n    </tr>\n    <tr>\n      <th>struct_asym_id</th>\n      <td>A</td>\n      <td>B</td>\n      <td>C</td>\n      <td>F</td>\n      <td>D</td>\n      <td>E</td>\n    </tr>\n    <tr>\n      <th>struct_asym_id_in_assembly</th>\n      <td>A</td>\n      <td>B</td>\n      <td>C</td>\n      <td>F</td>\n      <td>D</td>\n      <td>E</td>\n    </tr>\n    <tr>\n      <th>ca_p_only</th>\n      <td>False</td>\n      <td>False</td>\n      <td>False</td>\n      <td>False</td>\n      <td>False</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>gene_name</th>\n      <td>[\"PENT\",\"PNMT\"]</td>\n      <td>[\"PENT\",\"PNMT\"]</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>in_chains</th>\n      <td>[\"A\",\"B\"]</td>\n      <td>[\"A\",\"B\"]</td>\n      <td>[\"A\",\"B\"]</td>\n      <td>[\"A\",\"B\"]</td>\n      <td>[\"A\"]</td>\n      <td>[\"B\"]</td>\n    </tr>\n    <tr>\n      <th>in_struct_asyms</th>\n      <td>[\"A\",\"B\"]</td>\n      <td>[\"A\",\"B\"]</td>\n      <td>[\"C\",\"F\"]</td>\n      <td>[\"C\",\"F\"]</td>\n      <td>[\"D\"]</td>\n      <td>[\"E\"]</td>\n    </tr>\n    <tr>\n      <th>length</th>\n      <td>289</td>\n      <td>289</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>molecule_name</th>\n      <td>[\"Phenylethanolamine N-methyltransferase\"]</td>\n      <td>[\"Phenylethanolamine N-methyltransferase\"]</td>\n      <td>[\"S-ADENOSYL-L-HOMOCYSTEINE\"]</td>\n      <td>[\"S-ADENOSYL-L-HOMOCYSTEINE\"]</td>\n      <td>[\"N-(4-CHLOROPHENYL)-1,2,3,4-TETRAHYDROISOQUIN...</td>\n      <td>[\"PHOSPHATE ION\"]</td>\n    </tr>\n    <tr>\n      <th>molecule_type</th>\n      <td>polypeptide(L)</td>\n      <td>polypeptide(L)</td>\n      <td>bound</td>\n      <td>bound</td>\n      <td>bound</td>\n      <td>bound</td>\n    </tr>\n    <tr>\n      <th>mutation_flag</th>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>number_of_copies</th>\n      <td>2</td>\n      <td>2</td>\n      <td>2</td>\n      <td>2</td>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>pdb_sequence</th>\n      <td>MSGADRSPNAGAAPDSAPGQAAVASAYQRFEPRAYLRNNYAPPRGD...</td>\n      <td>MSGADRSPNAGAAPDSAPGQAAVASAYQRFEPRAYLRNNYAPPRGD...</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>pdb_sequence_indices_with_multiple_residues</th>\n      <td>{}</td>\n      <td>{}</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>sample_preparation</th>\n      <td>Genetically manipulated</td>\n      <td>Genetically manipulated</td>\n      <td>Synthetically obtained</td>\n      <td>Synthetically obtained</td>\n      <td>Synthetically obtained</td>\n      <td>Synthetically obtained</td>\n    </tr>\n    <tr>\n      <th>sequence</th>\n      <td>MSGADRSPNAGAAPDSAPGQAAVASAYQRFEPRAYLRNNYAPPRGD...</td>\n      <td>MSGADRSPNAGAAPDSAPGQAAVASAYQRFEPRAYLRNNYAPPRGD...</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>source</th>\n      <td>[{\"mappings\":[{\"start\":{\"residue_number\":1},\"e...</td>\n      <td>[{\"mappings\":[{\"start\":{\"residue_number\":1},\"e...</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>synonym</th>\n      <td>Phenylethanolamine N-methyltransferase</td>\n      <td>Phenylethanolamine N-methyltransferase</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>weight</th>\n      <td>31846</td>\n      <td>31846</td>\n      <td>384.411</td>\n      <td>384.411</td>\n      <td>322.81</td>\n      <td>94.971</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "metadata": {},
     "execution_count": 8
    }
   ],
   "source": [
    "# 配体被PISA识别为Protein\n",
    "pdb_2ony = PDB('2ony')\n",
    "pprint(pdb_2ony.fetch_from_web_api('api/pdb/entry/observed_residues_ratio/', PDB.orr2eec).result())\n",
    "pdb_2ony.get_res2eec_df().result().T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "Wall time: 0 ns\n"
    },
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "    author_insertion_code  author_residue_number multiple_conformers  \\\n0                                              1                 NaN   \n1                                              2                 NaN   \n2                                              3                 NaN   \n3                                              4                 NaN   \n4                                              5                 NaN   \n..                    ...                    ...                 ...   \n475                                          101                 NaN   \n476                                          302                 NaN   \n477                                          303                 NaN   \n478                                          103                 NaN   \n479                                          102                 NaN   \n\n     observed_ratio residue_name  residue_number chain_id struct_asym_id  \\\n0               1.0          MET               1        A              A   \n1               1.0          ASP               2        A              A   \n2               1.0          TYR               3        A              A   \n3               1.0          ARG               4        A              A   \n4               1.0          GLN               5        A              A   \n..              ...          ...             ...      ...            ...   \n475             1.0          GOL               1        D              L   \n476             1.0          GOL               1        B              G   \n477             1.0          EDO               1        B              H   \n478             1.0          EDO               1        C              K   \n479             1.0          EDO               1        C              J   \n\n    entity_id pdb_id  \n0           1   6ozg  \n1           1   6ozg  \n2           1   6ozg  \n3           1   6ozg  \n4           1   6ozg  \n..        ...    ...  \n475         4   6ozg  \n476         4   6ozg  \n477         5   6ozg  \n478         5   6ozg  \n479         5   6ozg  \n\n[480 rows x 10 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>author_insertion_code</th>\n      <th>author_residue_number</th>\n      <th>multiple_conformers</th>\n      <th>observed_ratio</th>\n      <th>residue_name</th>\n      <th>residue_number</th>\n      <th>chain_id</th>\n      <th>struct_asym_id</th>\n      <th>entity_id</th>\n      <th>pdb_id</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td></td>\n      <td>1</td>\n      <td>NaN</td>\n      <td>1.0</td>\n      <td>MET</td>\n      <td>1</td>\n      <td>A</td>\n      <td>A</td>\n      <td>1</td>\n      <td>6ozg</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td></td>\n      <td>2</td>\n      <td>NaN</td>\n      <td>1.0</td>\n      <td>ASP</td>\n      <td>2</td>\n      <td>A</td>\n      <td>A</td>\n      <td>1</td>\n      <td>6ozg</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td></td>\n      <td>3</td>\n      <td>NaN</td>\n      <td>1.0</td>\n      <td>TYR</td>\n      <td>3</td>\n      <td>A</td>\n      <td>A</td>\n      <td>1</td>\n      <td>6ozg</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td></td>\n      <td>4</td>\n      <td>NaN</td>\n      <td>1.0</td>\n      <td>ARG</td>\n      <td>4</td>\n      <td>A</td>\n      <td>A</td>\n      <td>1</td>\n      <td>6ozg</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td></td>\n      <td>5</td>\n      <td>NaN</td>\n      <td>1.0</td>\n      <td>GLN</td>\n      <td>5</td>\n      <td>A</td>\n      <td>A</td>\n      <td>1</td>\n      <td>6ozg</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>475</th>\n      <td></td>\n      <td>101</td>\n      <td>NaN</td>\n      <td>1.0</td>\n      <td>GOL</td>\n      <td>1</td>\n      <td>D</td>\n      <td>L</td>\n      <td>4</td>\n      <td>6ozg</td>\n    </tr>\n    <tr>\n      <th>476</th>\n      <td></td>\n      <td>302</td>\n      <td>NaN</td>\n      <td>1.0</td>\n      <td>GOL</td>\n      <td>1</td>\n      <td>B</td>\n      <td>G</td>\n      <td>4</td>\n      <td>6ozg</td>\n    </tr>\n    <tr>\n      <th>477</th>\n      <td></td>\n      <td>303</td>\n      <td>NaN</td>\n      <td>1.0</td>\n      <td>EDO</td>\n      <td>1</td>\n      <td>B</td>\n      <td>H</td>\n      <td>5</td>\n      <td>6ozg</td>\n    </tr>\n    <tr>\n      <th>478</th>\n      <td></td>\n      <td>103</td>\n      <td>NaN</td>\n      <td>1.0</td>\n      <td>EDO</td>\n      <td>1</td>\n      <td>C</td>\n      <td>K</td>\n      <td>5</td>\n      <td>6ozg</td>\n    </tr>\n    <tr>\n      <th>479</th>\n      <td></td>\n      <td>102</td>\n      <td>NaN</td>\n      <td>1.0</td>\n      <td>EDO</td>\n      <td>1</td>\n      <td>C</td>\n      <td>J</td>\n      <td>5</td>\n      <td>6ozg</td>\n    </tr>\n  </tbody>\n</table>\n<p>480 rows × 10 columns</p>\n</div>"
     },
     "metadata": {},
     "execution_count": 9
    }
   ],
   "source": [
    "%time pdb_6ozg.fetch_from_web_api('api/pdb/entry/residue_listing/', PDB.to_dataframe).result()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "Wall time: 1.53 s\n"
    },
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "{'bound': ('E', 'G', 'F', 'H'),\n 'carbohydrate polymer': ('C', 'D'),\n 'polypeptide(L)': ('A', 'B')}"
     },
     "metadata": {},
     "execution_count": 10
    }
   ],
   "source": [
    "%time pdb_2aw3.fetch_from_web_api('api/pdb/entry/assembly/', PDB.assembly2eec).result().groupby('molecule_type').struct_asym_id_in_assembly.apply(tuple).to_dict()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "{0: <PDBAssemble 1lo8/0>, 1: <PDBAssemble 1lo8/1>}"
     },
     "metadata": {},
     "execution_count": 11
    }
   ],
   "source": [
    "pdb_1lo8.set_assembly().result()\n",
    "pdb_1lo8.assembly"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "Wall time: 1.54 s\n"
    },
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "     buried_surface_area struct_asym_id_in_assembly author_insertion_code  \\\n0                    0.0                         AC                         \n1                    0.0                         AC                         \n2                    0.0                         AC                         \n3                    0.0                         AC                         \n4                    0.0                         AC                         \n..                   ...                        ...                   ...   \n135                  0.0                         AC                         \n136                  0.0                         AC                         \n137                  0.0                         AC                         \n138                  0.0                         AC                         \n139                  0.0                         AC                         \n\n    residue_name  author_residue_number  solvent_accessible_area  assembly_id  \\\n0            ALA                      2               114.288002            1   \n1            ARG                      3                95.989601            1   \n2            SER                      4                55.777199            1   \n3            ILE                      5                26.806700            1   \n4            THR                      6                78.233398            1   \n..           ...                    ...                      ...          ...   \n135          ILE                    137                52.862400            1   \n136          GLU                    138               129.716003            1   \n137          LEU                    139                72.225998            1   \n138          CYS                    140                 2.769540            1   \n139          SER                    141                85.012001            1   \n\n    s1_selection s2_selection  interface_id  ... entity_id chain_id  \\\n0             BC           AC             5  ...         1        A   \n1             BC           AC             5  ...         1        A   \n2             BC           AC             5  ...         1        A   \n3             BC           AC             5  ...         1        A   \n4             BC           AC             5  ...         1        A   \n..           ...          ...           ...  ...       ...      ...   \n135           BC           AC             5  ...         1        A   \n136           BC           AC             5  ...         1        A   \n137           BC           AC             5  ...         1        A   \n138           BC           AC             5  ...         1        A   \n139           BC           AC             5  ...         1        A   \n\n    struct_asym_id   molecule_type molecule_name                  details  \\\n0                A  polypeptide(L)           NaN  author_defined_assembly   \n1                A  polypeptide(L)           NaN  author_defined_assembly   \n2                A  polypeptide(L)           NaN  author_defined_assembly   \n3                A  polypeptide(L)           NaN  author_defined_assembly   \n4                A  polypeptide(L)           NaN  author_defined_assembly   \n..             ...             ...           ...                      ...   \n135              A  polypeptide(L)           NaN  author_defined_assembly   \n136              A  polypeptide(L)           NaN  author_defined_assembly   \n137              A  polypeptide(L)           NaN  author_defined_assembly   \n138              A  polypeptide(L)           NaN  author_defined_assembly   \n139              A  polypeptide(L)           NaN  author_defined_assembly   \n\n    asym_id_rank  multiple_conformers observed_ratio  residue_number  \n0              4                  NaN              1               2  \n1              4                  NaN              1               3  \n2              4                  NaN              1               4  \n3              4                  NaN              1               5  \n4              4                  NaN              1               6  \n..           ...                  ...            ...             ...  \n135            4                  NaN              1             137  \n136            4                  NaN              1             138  \n137            4                  NaN              1             139  \n138            4                  NaN              1             140  \n139            4                  NaN              1             141  \n\n[140 rows x 21 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>buried_surface_area</th>\n      <th>struct_asym_id_in_assembly</th>\n      <th>author_insertion_code</th>\n      <th>residue_name</th>\n      <th>author_residue_number</th>\n      <th>solvent_accessible_area</th>\n      <th>assembly_id</th>\n      <th>s1_selection</th>\n      <th>s2_selection</th>\n      <th>interface_id</th>\n      <th>...</th>\n      <th>entity_id</th>\n      <th>chain_id</th>\n      <th>struct_asym_id</th>\n      <th>molecule_type</th>\n      <th>molecule_name</th>\n      <th>details</th>\n      <th>asym_id_rank</th>\n      <th>multiple_conformers</th>\n      <th>observed_ratio</th>\n      <th>residue_number</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>0.0</td>\n      <td>AC</td>\n      <td></td>\n      <td>ALA</td>\n      <td>2</td>\n      <td>114.288002</td>\n      <td>1</td>\n      <td>BC</td>\n      <td>AC</td>\n      <td>5</td>\n      <td>...</td>\n      <td>1</td>\n      <td>A</td>\n      <td>A</td>\n      <td>polypeptide(L)</td>\n      <td>NaN</td>\n      <td>author_defined_assembly</td>\n      <td>4</td>\n      <td>NaN</td>\n      <td>1</td>\n      <td>2</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>0.0</td>\n      <td>AC</td>\n      <td></td>\n      <td>ARG</td>\n      <td>3</td>\n      <td>95.989601</td>\n      <td>1</td>\n      <td>BC</td>\n      <td>AC</td>\n      <td>5</td>\n      <td>...</td>\n      <td>1</td>\n      <td>A</td>\n      <td>A</td>\n      <td>polypeptide(L)</td>\n      <td>NaN</td>\n      <td>author_defined_assembly</td>\n      <td>4</td>\n      <td>NaN</td>\n      <td>1</td>\n      <td>3</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>0.0</td>\n      <td>AC</td>\n      <td></td>\n      <td>SER</td>\n      <td>4</td>\n      <td>55.777199</td>\n      <td>1</td>\n      <td>BC</td>\n      <td>AC</td>\n      <td>5</td>\n      <td>...</td>\n      <td>1</td>\n      <td>A</td>\n      <td>A</td>\n      <td>polypeptide(L)</td>\n      <td>NaN</td>\n      <td>author_defined_assembly</td>\n      <td>4</td>\n      <td>NaN</td>\n      <td>1</td>\n      <td>4</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>0.0</td>\n      <td>AC</td>\n      <td></td>\n      <td>ILE</td>\n      <td>5</td>\n      <td>26.806700</td>\n      <td>1</td>\n      <td>BC</td>\n      <td>AC</td>\n      <td>5</td>\n      <td>...</td>\n      <td>1</td>\n      <td>A</td>\n      <td>A</td>\n      <td>polypeptide(L)</td>\n      <td>NaN</td>\n      <td>author_defined_assembly</td>\n      <td>4</td>\n      <td>NaN</td>\n      <td>1</td>\n      <td>5</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>0.0</td>\n      <td>AC</td>\n      <td></td>\n      <td>THR</td>\n      <td>6</td>\n      <td>78.233398</td>\n      <td>1</td>\n      <td>BC</td>\n      <td>AC</td>\n      <td>5</td>\n      <td>...</td>\n      <td>1</td>\n      <td>A</td>\n      <td>A</td>\n      <td>polypeptide(L)</td>\n      <td>NaN</td>\n      <td>author_defined_assembly</td>\n      <td>4</td>\n      <td>NaN</td>\n      <td>1</td>\n      <td>6</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>135</th>\n      <td>0.0</td>\n      <td>AC</td>\n      <td></td>\n      <td>ILE</td>\n      <td>137</td>\n      <td>52.862400</td>\n      <td>1</td>\n      <td>BC</td>\n      <td>AC</td>\n      <td>5</td>\n      <td>...</td>\n      <td>1</td>\n      <td>A</td>\n      <td>A</td>\n      <td>polypeptide(L)</td>\n      <td>NaN</td>\n      <td>author_defined_assembly</td>\n      <td>4</td>\n      <td>NaN</td>\n      <td>1</td>\n      <td>137</td>\n    </tr>\n    <tr>\n      <th>136</th>\n      <td>0.0</td>\n      <td>AC</td>\n      <td></td>\n      <td>GLU</td>\n      <td>138</td>\n      <td>129.716003</td>\n      <td>1</td>\n      <td>BC</td>\n      <td>AC</td>\n      <td>5</td>\n      <td>...</td>\n      <td>1</td>\n      <td>A</td>\n      <td>A</td>\n      <td>polypeptide(L)</td>\n      <td>NaN</td>\n      <td>author_defined_assembly</td>\n      <td>4</td>\n      <td>NaN</td>\n      <td>1</td>\n      <td>138</td>\n    </tr>\n    <tr>\n      <th>137</th>\n      <td>0.0</td>\n      <td>AC</td>\n      <td></td>\n      <td>LEU</td>\n      <td>139</td>\n      <td>72.225998</td>\n      <td>1</td>\n      <td>BC</td>\n      <td>AC</td>\n      <td>5</td>\n      <td>...</td>\n      <td>1</td>\n      <td>A</td>\n      <td>A</td>\n      <td>polypeptide(L)</td>\n      <td>NaN</td>\n      <td>author_defined_assembly</td>\n      <td>4</td>\n      <td>NaN</td>\n      <td>1</td>\n      <td>139</td>\n    </tr>\n    <tr>\n      <th>138</th>\n      <td>0.0</td>\n      <td>AC</td>\n      <td></td>\n      <td>CYS</td>\n      <td>140</td>\n      <td>2.769540</td>\n      <td>1</td>\n      <td>BC</td>\n      <td>AC</td>\n      <td>5</td>\n      <td>...</td>\n      <td>1</td>\n      <td>A</td>\n      <td>A</td>\n      <td>polypeptide(L)</td>\n      <td>NaN</td>\n      <td>author_defined_assembly</td>\n      <td>4</td>\n      <td>NaN</td>\n      <td>1</td>\n      <td>140</td>\n    </tr>\n    <tr>\n      <th>139</th>\n      <td>0.0</td>\n      <td>AC</td>\n      <td></td>\n      <td>SER</td>\n      <td>141</td>\n      <td>85.012001</td>\n      <td>1</td>\n      <td>BC</td>\n      <td>AC</td>\n      <td>5</td>\n      <td>...</td>\n      <td>1</td>\n      <td>A</td>\n      <td>A</td>\n      <td>polypeptide(L)</td>\n      <td>NaN</td>\n      <td>author_defined_assembly</td>\n      <td>4</td>\n      <td>NaN</td>\n      <td>1</td>\n      <td>141</td>\n    </tr>\n  </tbody>\n</table>\n<p>140 rows × 21 columns</p>\n</div>"
     },
     "metadata": {},
     "execution_count": 12
    }
   ],
   "source": [
    "pdb_1lo8.get_assembly(1).pipe_protein_ligand_interface().result()\n",
    "pdb_1lo8_1_5 = pdb_1lo8.get_assembly(1).get_interface(5)\n",
    "%time pdb_1lo8_1_5.get_interface_res_df().result()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "{'entity_id_1': '1',\n 'chain_id_1': 'A',\n 'struct_asym_id_1': 'A',\n 'struct_asym_id_in_assembly_1': 'AC',\n 'asym_id_rank_1': 4,\n 'molecule_type_1': 'polypeptide(L)',\n 'molecule_name_1': nan,\n 'surface_range_1': '[[2,91],[93,93],[95,110],[112,118],[120,141]]',\n 'interface_range_1': '[[32,32],[36,36],[47,47],[57,63],[88,91],[116,118],[120,120],[127,129]]',\n 'struct_asym_id_in_assembly_2': 'BC',\n 'molecule_name_2': nan,\n 'asym_id_rank_2': 4,\n 'molecule_type_2': 'bound',\n 'entity_id_2': '2',\n 'struct_asym_id_2': 'B',\n 'chain_id_2': 'A',\n 'pdb_id': '1lo8',\n 'assembly_id': 1,\n 'interface_id': 5}"
     },
     "metadata": {},
     "execution_count": 13
    }
   ],
   "source": [
    "pdb_1lo8_1_5.get_interface_res_dict().result()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "@unsync\n",
    "async def pipe(pdb: PDB):\n",
    "    await pdb.set_assembly(focus_assembly_ids={0})\n",
    "    for assembly in pdb.assembly.values():\n",
    "        await assembly.pipe_protein_ligand_interface()\n",
    "        for interface in assembly.interface.values():\n",
    "            await interface.set_interface_res()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "Wall time: 7.69 s\n"
    },
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "  entity_id_1 chain_id_1 struct_asym_id_1 struct_asym_id_in_assembly_1  \\\n0           1          B                B                            B   \n1           1          A                A                            A   \n2           1          B                B                            B   \n\n   asym_id_rank_1 molecule_type_1                             molecule_name_1  \\\n0               1  polypeptide(L)  [\"Phenylethanolamine N-methyltransferase\"]   \n1               1  polypeptide(L)  [\"Phenylethanolamine N-methyltransferase\"]   \n2               1  polypeptide(L)  [\"Phenylethanolamine N-methyltransferase\"]   \n\n                                     surface_range_1  \\\n0  [[14,86],[88,90],[92,96],[98,99],[101,126],[12...   \n1  [[24,90],[92,96],[98,99],[101,126],[128,174],[...   \n2  [[14,86],[88,90],[92,96],[98,99],[101,126],[12...   \n\n                                   interface_range_1 entity_id_2  ...  \\\n0  [[23,24],[27,27],[30,30],[35,35],[40,40],[77,8...           2  ...   \n1  [[24,24],[27,27],[30,30],[35,35],[40,40],[79,8...           2  ...   \n2  [[35,35],[39,40],[44,44],[53,53],[57,57],[182,...           4  ...   \n\n  struct_asym_id_2 struct_asym_id_in_assembly_2 asym_id_rank_2  \\\n0                F                            F              1   \n1                C                            C              1   \n2                E                            E              1   \n\n   molecule_type_2                molecule_name_2 surface_range_2  \\\n0            bound  [\"S-ADENOSYL-L-HOMOCYSTEINE\"]         [[1,1]]   \n1            bound  [\"S-ADENOSYL-L-HOMOCYSTEINE\"]         [[1,1]]   \n2            bound              [\"PHOSPHATE ION\"]             NaN   \n\n  interface_range_2 pdb_id assembly_id  interface_id  \n0           [[1,1]]   2ony           0             4  \n1           [[1,1]]   2ony           0             5  \n2               NaN   2ony           0             8  \n\n[3 rows x 21 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>entity_id_1</th>\n      <th>chain_id_1</th>\n      <th>struct_asym_id_1</th>\n      <th>struct_asym_id_in_assembly_1</th>\n      <th>asym_id_rank_1</th>\n      <th>molecule_type_1</th>\n      <th>molecule_name_1</th>\n      <th>surface_range_1</th>\n      <th>interface_range_1</th>\n      <th>entity_id_2</th>\n      <th>...</th>\n      <th>struct_asym_id_2</th>\n      <th>struct_asym_id_in_assembly_2</th>\n      <th>asym_id_rank_2</th>\n      <th>molecule_type_2</th>\n      <th>molecule_name_2</th>\n      <th>surface_range_2</th>\n      <th>interface_range_2</th>\n      <th>pdb_id</th>\n      <th>assembly_id</th>\n      <th>interface_id</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>1</td>\n      <td>B</td>\n      <td>B</td>\n      <td>B</td>\n      <td>1</td>\n      <td>polypeptide(L)</td>\n      <td>[\"Phenylethanolamine N-methyltransferase\"]</td>\n      <td>[[14,86],[88,90],[92,96],[98,99],[101,126],[12...</td>\n      <td>[[23,24],[27,27],[30,30],[35,35],[40,40],[77,8...</td>\n      <td>2</td>\n      <td>...</td>\n      <td>F</td>\n      <td>F</td>\n      <td>1</td>\n      <td>bound</td>\n      <td>[\"S-ADENOSYL-L-HOMOCYSTEINE\"]</td>\n      <td>[[1,1]]</td>\n      <td>[[1,1]]</td>\n      <td>2ony</td>\n      <td>0</td>\n      <td>4</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>1</td>\n      <td>A</td>\n      <td>A</td>\n      <td>A</td>\n      <td>1</td>\n      <td>polypeptide(L)</td>\n      <td>[\"Phenylethanolamine N-methyltransferase\"]</td>\n      <td>[[24,90],[92,96],[98,99],[101,126],[128,174],[...</td>\n      <td>[[24,24],[27,27],[30,30],[35,35],[40,40],[79,8...</td>\n      <td>2</td>\n      <td>...</td>\n      <td>C</td>\n      <td>C</td>\n      <td>1</td>\n      <td>bound</td>\n      <td>[\"S-ADENOSYL-L-HOMOCYSTEINE\"]</td>\n      <td>[[1,1]]</td>\n      <td>[[1,1]]</td>\n      <td>2ony</td>\n      <td>0</td>\n      <td>5</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>1</td>\n      <td>B</td>\n      <td>B</td>\n      <td>B</td>\n      <td>1</td>\n      <td>polypeptide(L)</td>\n      <td>[\"Phenylethanolamine N-methyltransferase\"]</td>\n      <td>[[14,86],[88,90],[92,96],[98,99],[101,126],[12...</td>\n      <td>[[35,35],[39,40],[44,44],[53,53],[57,57],[182,...</td>\n      <td>4</td>\n      <td>...</td>\n      <td>E</td>\n      <td>E</td>\n      <td>1</td>\n      <td>bound</td>\n      <td>[\"PHOSPHATE ION\"]</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>2ony</td>\n      <td>0</td>\n      <td>8</td>\n    </tr>\n  </tbody>\n</table>\n<p>3 rows × 21 columns</p>\n</div>"
     },
     "metadata": {},
     "execution_count": 15
    }
   ],
   "source": [
    "%time pipe(pdb_2ony).result()\n",
    "pd.DataFrame([interface.get_interface_res_dict().result() for assembly in pdb_2ony.assembly.values() for interface in assembly.interface.values()])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "{'structure_2.symmetry_operator': ('eq', 'x,y,z'),\n 'css': ('gt', 0),\n 'struct_asym_id_in_assembly_1': ('isin', set()),\n 'struct_asym_id_in_assembly_2': ('isin', set())}"
     },
     "metadata": {},
     "execution_count": 23
    }
   ],
   "source": [
    "pdb_1lo8.assembly[0].interface_filters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "                                                                              0  \\\nspacegroup                                                                  P 1   \nstructure_name                                                         PDB 2q88   \ntitle                         Crystal structure of EhuB in complex with ectoine   \nstruct_asym_id_in_assembly_1                                                  F   \nstruct_asym_id_in_assembly_2                                                  A   \n\n                                                                              1  \nspacegroup                                                                  P 1  \nstructure_name                                                         PDB 2q88  \ntitle                         Crystal structure of EhuB in complex with ectoine  \nstruct_asym_id_in_assembly_1                                                  E  \nstruct_asym_id_in_assembly_2                                                  A  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>0</th>\n      <th>1</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>spacegroup</th>\n      <td>P 1</td>\n      <td>P 1</td>\n    </tr>\n    <tr>\n      <th>structure_name</th>\n      <td>PDB 2q88</td>\n      <td>PDB 2q88</td>\n    </tr>\n    <tr>\n      <th>title</th>\n      <td>Crystal structure of EhuB in complex with ectoine</td>\n      <td>Crystal structure of EhuB in complex with ectoine</td>\n    </tr>\n    <tr>\n      <th>struct_asym_id_in_assembly_1</th>\n      <td>F</td>\n      <td>E</td>\n    </tr>\n    <tr>\n      <th>struct_asym_id_in_assembly_2</th>\n      <td>A</td>\n      <td>A</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "metadata": {},
     "execution_count": 16
    }
   ],
   "source": [
    "# pdb_6ozg\n",
    "pdb_2q88.set_assembly().result()\n",
    "pdb_2q88.get_assembly(1).fetch_from_web_api('api/pisa/interfacelist/', PDBAssemble.to_interfacelist_df).result().head(2).T.tail(5)\n",
    "# %time PDB('1oo9').fetch_from_web_api('api/mappings/all_isoforms/', PDB.to_dataframe).result()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "  struct_asym_id_in_assembly_1 structure_1.range struct_asym_id_in_assembly_2  \\\n0                            F                 F                            A   \n1                            E         [CD]E:604                            A   \n2                            D         [CD]D:603                            A   \n3                            B         [CD]B:601                            A   \n4                            C         [CD]C:602                            A   \n\n  structure_2.range  \n0                 A  \n1                 A  \n2                 A  \n3                 A  \n4                 A  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>struct_asym_id_in_assembly_1</th>\n      <th>structure_1.range</th>\n      <th>struct_asym_id_in_assembly_2</th>\n      <th>structure_2.range</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>F</td>\n      <td>F</td>\n      <td>A</td>\n      <td>A</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>E</td>\n      <td>[CD]E:604</td>\n      <td>A</td>\n      <td>A</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>D</td>\n      <td>[CD]D:603</td>\n      <td>A</td>\n      <td>A</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>B</td>\n      <td>[CD]B:601</td>\n      <td>A</td>\n      <td>A</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>C</td>\n      <td>[CD]C:602</td>\n      <td>A</td>\n      <td>A</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "metadata": {},
     "execution_count": 17
    }
   ],
   "source": [
    "pdb_2q88.get_assembly(1).fetch_from_web_api('api/pisa/interfacelist/', PDBAssemble.to_interfacelist_df).result()[['struct_asym_id_in_assembly_1', 'structure_1.range', 'struct_asym_id_in_assembly_2', 'structure_2.range']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ]
}